#coding=utf-8
#!/usr/bin/python

'''
Created on 2012-11-17

@author: Neo.Chen
'''

#
# 这里去掉了循环检查，改为用linux系统计划任务来执行，五分钟执行一次
# */5 * * * * python /opt/python/vcs_livecheck.py vcs_live /opt/python/run_live.sh
#

import os
import sys
sys.path.append("../")
import time
import string
import threading
from ktlib import ktlib
from ktlib import proc_monitor

#默认命令行参数
g_process_name = "vcs_test"     #进程名字
g_bash_name = "./run_test.sh"   #启动脚本名字，放自己同一个目录

def app_restart(content):
    #重启进程
    os.system(g_bash_name)
    #发邮件通知
    ktlib.send_email("admin@sky-mobi.com", "neo.chen@sky-mobi.com", g_process_name + " restart", content)
    ktlib.send_email("admin@sky-mobi.com", "18758166494@139.com", g_process_name + " restart", content)
    ktlib.send_email("admin@sky-mobi.com", "tristan.yang@sky-mobi.com", g_process_name + " restart", content)
    ktlib.send_email("admin@sky-mobi.com", "13958110295@139.com", g_process_name + " restart", content)
    print("restart**********,content:", content , "\r\n")

def main():
    print("main start...")
    proc = proc_monitor.CProcCpuMonitor(g_process_name, 50, 0, 1)
    isError = False
    fCpu = 0.0
    (isError, fCpu)= proc.checkIsError()
    print("proc.checkIsError, isError:", isError, ", cpu:", fCpu)
    if isError == True:
    #    app_restart("cpu is:%.1f, time:%s" % (fCpu, time.asctime()))
        print("$$$$$$$$$")

if __name__ == '__main__':
    if len(sys.argv) > 1:
        g_process_name = sys.argv[1]
        g_bash_name = sys.argv[2]
        print(g_process_name)
        print(g_bash_name)
        main()
    else:
        print("cmd line param: vcs_test ./run_test.sh")

